//
//  WBTabBarController.swift
//  myWeibo
//
//  Created by 何达达mac on 2018/5/26.
//  Copyright © 2018年 hedada. All rights reserved.
//

import UIKit

class WBTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

             setupChildControllers()
        
    }



}
extension WBTabBarController{
     func setupChildControllers(){
          let  array = [["clsName" : "WBHomeViewController","title":"首页","imageName":"tabBar_essence_icon","selectedImage":"tabBar_essence_click_icon"],
                              ["clsName" : "WBMessageViewController","title":"消息","imageName":"tabBar_friendTrends_icon","selectedImage":"tabBar_friendTrends_click_icon"],
                              ["clsName" : "WBDiscroveViewController","title":"发现","imageName":"tabBar_new_icon","selectedImage":"tabBar_new_click_icon"],
                              ["clsName" : "WBProfileViewController","title":"我的","imageName":"tabBar_me_icon","selectedImage":"tabBar_me_click_icon"]]
        
         for  dict in array {
            self.addChildViewController(self.controllers(dict:dict ))
        }
        
    }
    
    private func controllers(dict:[String : String])->UIViewController{
            guard   let clsName = dict["clsName"],
                        let title = dict["title"],
                        let imageName = dict["imageName"],
                        let selectedImage = dict["selectedImage"],
                        let cls = NSClassFromString(Bundle.main.nameSpace + "." + clsName) as? UIViewController.Type   else{
            
                            return UIViewController()
        }
        let vc = cls.init()
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)?.withRenderingMode(.alwaysOriginal)
        vc.tabBarItem.selectedImage = UIImage(named: selectedImage)?.withRenderingMode(.alwaysOriginal)
        //设置字体大小和颜色
        var textAttrs: [String : AnyObject] = Dictionary()
        textAttrs[NSForegroundColorAttributeName] = UIColor.purple
        textAttrs[NSFontAttributeName] = UIFont.systemFont(ofSize: 16)
        vc.tabBarItem.setTitleTextAttributes(textAttrs, for: .highlighted)

        let nav = WBNavigationController(rootViewController: vc)
        return nav
      
    }
    
    
    
}
